package Test2;

public class Triangle extends Shape{
    private double a ;
    private double b;
    private double c;


    public Triangle(double a, double b, double c) {
        if (a+b > c && a + c > b && b + c> a) {
            this.a = a;
            this.b = b;
            this.c = c;
        }else {
           System.out.println("请重新输入三角形的三边：a，b，c");
        }

    }

    @Override
    public double area() {
        // 计算半周长
        double p = (a + b + c) / 2;

        // 使用海伦公式计算面积
        double area = Math.sqrt(p * (p - a) * (p - b) * (p - c));

        return area;
    }



    @Override
    public double perimeter() {
        return a + b +c ;
    }

    @Override
    public String toString() {
        return String.valueOf("三角形面积：" + area() + "三角形周长：" + perimeter());
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }



}
